// 首页
// http://106.52.240.230:12368/

// 登录
// http://106.52.240.230:12368/#/login

// 接单
// http://106.52.240.230:84/index.php/User/Task/ceshi


function openHome() {
    let token = Android.getMap("token")
    if (!token) {
        return
    }
    let l = token.split(",")
    let obj = {
        "userid": l[0], 
        "username": l[1], 
        "userInfo": { 
            "status": 1, 
            "msg": "登录成功！", 
            "userid": l[0], 
            "username": l[1], 
            "bindcert": "1", 
            "bindbank": "1", 
            "bindalipay": "1", 
            "bindqq": "0", 
            "buyreqrate": "60" 
        }, 
        "hadOpened": true, 
        "isIndexShow": true
    }
    localStorage.setItem("Login", JSON.stringify(obj))
}
openHome()


// 获取toke
function getAndroidToken() {
    let obj = JSON.parse(localStorage.getItem("Login"))
    let userid = obj["userid"]
    let username = obj["username"]
    return userid + "," + username
}
getAndroidToken()



// 接单
function getParameterHandler() {
    let token = parameter.getMap("token")
    if (!token) {
        return
    }
    let l = token.split(",")
    let headers = {}
    let body = {
        "username": l[1],
        "userid": l[0]
    }
    let strUrl = ``
    let url = parameter.getMap("url") + strUrl
    return {
        mediaType: "form",
        requestType: "POST",
        url: url,
        headers: JSON.stringify(headers),
        body: JSON.stringify(body)
    }
}
getParameterHandler()



// 处理返回数据
function getResponse() {
    let res = response.getMap("res")
    res = JSON.parse(res)

    let code = "500"
    let message = res["msg"]
    if (res["status"] == 1) {
        code = "200"
    } else if (res["status"] == 3 || res["status"] == 100) {
        code = "500"
    } else {
        code = "300"
    }
    let decodedStr = message.replace(/\\u([\d\w]{4})/gi, (match, p1) =>
        String.fromCharCode(parseInt(p1, 16))
    );
    return {
        code: code,
        message: decodedStr,
        dataKey: "",
        dataValue: ""
    }
}
getResponse()